﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using Sdkbox;

public class Buy : MonoBehaviour {

	IAP iap;

	// Use this for initialization
	void Start () {

		GameObject.Find ("Canvas/Buy").GetComponent<Button> ().onClick.AddListener (BuyAction);

		iap = GameObject.Find ("IAP").GetComponent<IAP> (); 

		iap.callbacks.onInitialized.AddListener(onInitialized);
		iap.callbacks.onSuccess.AddListener (onSuccess);
		iap.callbacks.onFailure.AddListener (onFailure);
		iap.callbacks.onCanceled.AddListener (onCanceled);
		iap.callbacks.onRestored.AddListener (onRestored);
		iap.callbacks.onProductRequestSuccess.AddListener (onProductRequestSuccess);
		iap.callbacks.onProductRequestFailure.AddListener (onProductRequestFailure);
		iap.callbacks.onRestoreComplete.AddListener (onRestoreComplete);
	}
	
	void BuyAction() {
		iap.purchase ("mybread");
	}

	// purchase callback
	void onInitialized(bool param) {
		Debug.LogFormat ("Initialize result: {0} ", param.ToString());
	}

	void onSuccess(Sdkbox.Product product) {
		Debug.LogFormat ("Buy success: {0} ", product.name);
	}

	void onFailure(Sdkbox.Product product, string message) {
		Debug.Log ("Buy failed.");
	}

	void onCanceled(Sdkbox.Product product) {
		Debug.Log ("User cancelled");
	}

	void onRestored(Sdkbox.Product product) {

	}

	void onProductRequestSuccess(Sdkbox.Product[] product) {
		Debug.Log ("onProductRequestSuccess");
	}

	void onProductRequestFailure(string message) {
		Debug.Log ("onProductRequestFailure");
	}

	void onRestoreComplete(bool result, string message) {

	}
}
